package lipengfei.botaiframework.validate.validator;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


import cn.hutool.core.util.StrUtil;
import lipengfei.botaiframework.validate.annotation.MobilePhone;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 手机号校验
 */
public class MobilePhoneValidator  implements ConstraintValidator<MobilePhone, String> {
    private static final Pattern PATTERN = Pattern.compile("^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(16[5,6])|(17[0-8])|(18[0-9])|(19[1、5、8、9]))\\d{8}$");

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 不为null才进行校验
        if (StrUtil.isNotBlank(value)) {
            Matcher matcher = PATTERN.matcher(value);
            return matcher.find();
        }
        return true;
    }
    
    
}
